package com.example.simpleplayer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.media.MediaExtractor;
import android.os.Bundle;
import android.os.Handler;
import android.view.SurfaceView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_EXTERNAL_STORAGE = 1;

    private static String[] PERMISSIONS_STORAGE = {
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        verifyStoragePermissions(this);


        // Example of a call to a native method

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                SurfaceView surfaceView = findViewById(R.id.surface);
                MediaPlayer mediaPlayer = new MediaPlayer();
                mediaPlayer.setSurface(surfaceView.getHolder().getSurface());
//                mediaPlayer.setDataSource("/sdcard/火箭少女101-风[国][1080P].mpg");
//                mediaPlayer.setDataSource("/sdcard/testfile.mp4");
                mediaPlayer.setDataSource("/sdcard/Breaking.mkv");

                mediaPlayer.start();
//        TextView tv = findViewById(R.id.sample_text);
//        tv.setText(stringFromJNI());
            }
        },1200);

    }


    public static void verifyStoragePermissions(Activity activity) {
        try {
            //检测是否有写的权限
            int permission = ActivityCompat.checkSelfPermission(activity,
                    "android.permission.WRITE_EXTERNAL_STORAGE");
            if (permission != PackageManager.PERMISSION_GRANTED) {
                // 没有写的权限，去申请写的权限，会弹出对话框
                ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}